using System;
using System.Web.UI.WebControls;

namespace Matrix_network.PeopleLists
{
    public partial class PeopleSearch : System.Web.UI.Page
    {
        protected void AddFriendBtn_OnClick(object sender, EventArgs e)
        {
            var btn = (LinkButton)sender;
            btn.Text = (string)GetLocalResourceObject("AddedToFriends");
            btn.Enabled = false;
            int friendId = Int32.Parse(btn.CommandArgument);

            int usrId = User.Identity.UserId();
            //forbid to add and write to yourself
            if (usrId == friendId)
            {
                btn.Text = (string)GetLocalResourceObject("CantAddYourself");
                return;
            }

            //add friend to database
            new MatrixData().addFriend(usrId, friendId);
        }

        protected void WriteBtn_OnClick(object sender, EventArgs e)
        {
            var btn = (LinkButton)sender;
            btn.Enabled = false;
            int friendId = Int32.Parse(btn.CommandArgument);

            int usrId = User.Identity.UserId();
            //forbid to add and write to yourself
            if (usrId == friendId)
            {
                btn.Text = (string)GetLocalResourceObject("CantWriteYourself");
                return;
            }

            //redirect to write message page
            Response.Redirect("~/SendMessage.aspx?toId=" + friendId);
        }
    }
}